﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Security.Cryptography;

namespace command
{
    public class Class1
    {
        //连接地址      
        public static string cn;//当前连接字串
        //用户英文名,用户中文名
        public static string ename; //英文名
        /// <summary>
        /// 中文名
        /// </summary>
        public static string cname; 
        public static int Roleid;//角色ID
        public static string Rolename;//角色名称
        public static string version="";//版本号
        public static string kstate;//描述状态,暂时还未使用
        public static string company="";//公司名称    
        public static int proint = 0;//程序加载的天数
        //public static int codelength=0;//编码长度
        //数组,专门用来复制
        public static string[] ssak = new string[10];
        /// <summary>
        /// 传音验证是否PE大袋扫描过
        /// </summary>
        public static bool TECTM14check = false;//传音验证是否PE大袋扫描过      
        
        //专门用来执行sqldataread查询, 返回值也是sqldataread
        public static SqlDataReader sqlreader(string strread)
        {
            SqlConnection cna = new SqlConnection(cn);
            SqlCommand cmd = new SqlCommand(strread, cna);
            cna.Open();
            SqlDataReader thisread = cmd.ExecuteReader();
            cna.Close();
            return thisread;
        }
        ////清除各控件内容,
        //public static void qingkong(Control frm) //将所有的控件清空
        //{
        //    foreach (Control ct in frm.Controls)
        //    {
        //        if (ct is TextBox)
        //        {
        //            ct.Text = null;
        //        }
        //        else if (ct is DateTimePicker)
        //            ct.Text = null;
        //        else if (ct is ComboBox)//文本框
        //            ct.Text = null;
        //        else if (ct is CheckBox)//选择框
        //            (ct as CheckBox).Checked = false;   
        //    }
        //}
        //public static void cleardatagridview(DataGridView dgv)//将datagridview清空内容
        //{
        //    int columnCount = dgv.ColumnCount;
        //    int rowCount = dgv.Rows.Count;
        //    for (int i = 0; i < rowCount; i++)
        //    {
        //        for (int j = 0; j < columnCount; j++)
        //        {
        //            dgv.Rows[i].Cells[j].Value = "";
        //        }
        //    }
        //}
        //public static void cleardatagridviewNULL(DataGridView dgv)//将datagridview清空内容
        //{
        //    int columnCount = dgv.ColumnCount;
        //    int rowCount = dgv.Rows.Count;
        //    for (int i = 0; i < rowCount; i++)
        //    {
        //        for (int j = 0; j < columnCount; j++)
        //        {
        //            dgv.Rows[i].Cells[j].Value = null;
        //        }
        //    }
        //}
        //public static void cleardatabindings(Control frm) //清除绑定
        //{
        //    foreach (Control ct in frm.Controls)
        //    {
        //        ct.DataBindings.Clear();
        //    }
        //}
      
        //public static object sqnulldate(object obnull) //返回NULL 或者是DBNULL 针对row日期要返回DBNULL(有条件下的使用日期)
        //{

        //    if (string.IsNullOrEmpty(obnull.ToString()))
        //    {
        //        obnull = DBNull.Value;
        //    }
        //    return obnull;
        //}

        //public static bool deleform(Form his) //返回decimal数字
        //{
        //    bool bl = false;
        //    DialogResult dgr = MessageBox.Show(his, "你确定要删除吗？", "删除通知", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        //    if (dgr == DialogResult.Yes)
        //    {
        //        bl = true;
        //    }
        //    return bl;
        //}

        //密码改成二进制,采用暗文不是明文
        public static byte[] EncryptPassword(string password)
        {
            UnicodeEncoding encoding = new UnicodeEncoding();
            byte[] hashBytes = encoding.GetBytes(password);
            SHA1 sha1 = new SHA1CryptoServiceProvider();
            byte[] cryptPassword = sha1.ComputeHash(hashBytes);
            return cryptPassword;
        }
   
    }
}
